#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

using namespace std;
using LL = long long;

const int N = 2e5 + 10;

int n;
int q[N];
LL dp[N];

int main()
{

    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    int T;
    cin >> T;
    while(T--){
        memset(dp, 0, sizeof dp);
        cin >> n;
        for (int i = 0; i < n; i ++){
            cin >> q[i];
        }

        for (int i = 1; i < n; i ++){
            if(q[i - 1] > 0){
                dp[i] = dp[i - 1] + q[i - 1];
            } else if(q[i - 1] == 0){
                if(dp[i - 1] == 0){
                    dp[i] = 0;
                }else{
                    dp[i] = dp[i - 1] + 1;
                }
            }
        }

        printf("%lld\n", dp[n - 1]);
    }

    return 0;
}